<template>
  <kr-print-designer  :temp-value="value" :widget-options="widgets" @save="handleSave" />
</template>
<script>
import { ReceiptOptions,PaymentOptions } from './data/options'
import { getPrintTemplet, updatePrintTemplet } from "@/api/system/printTemplet";
export default {
  data() {
    return {
      tempId: null,
      value: {},
      widgets: ReceiptOptions,
      printTemplet:{}
    }
  },

  created() {
    this.printTemplet = JSON.parse(localStorage.getItem('tempRow'))
    this.value['title'] = this.printTemplet.title
    this.value['width'] = this.printTemplet.width
    this.value['height'] = this.printTemplet.height
    this.value['pageWidth'] = this.printTemplet.pageWidth
    this.value['pageHeight'] = this.printTemplet.pageHeight
    this.value['tempItems'] = JSON.parse(this.printTemplet.tempContent||'[]')
    switch (this.printTemplet.templetType) {
      case '10':
        //收款组件
        this.widgets = ReceiptOptions
        break;
      case '20':
        //付款组件
        this.widgets = PaymentOptions
        break;
      default:
        break;
    }
  },
  methods: {
    handleSave(data) {
      this.printTemplet.title = data.title
      this.printTemplet.width = data.width
      this.printTemplet.height = data.height
      this.printTemplet.pageWidth = data.pageWidth
      this.printTemplet.pageHeight = data.pageHeight
      this.printTemplet.tempContent = JSON.stringify(data.tempItems)
      updatePrintTemplet(this.printTemplet).then(res=>{
        this.msgSuccess("保存成功")
        this.$router.back()
      })
    },
  },
}
</script>
